
class Goods(object):

    def __init__(self):
        self.test1 = "1"

    def __getitem__(self, item):
        print("获取item = %s" % item)

    def __setitem__(self, key, value):
        print("设置key = %s, value = %s" % (key, value))

    def __delitem__(self, key):
        print("删除key= %s" % key)


if __name__ == '__main__':
    g = Goods()

    # 调用__getitem__方法
    g['a']

    # 调用__setitem__方法
    g['a'] = 100
    g['a']

    # 调用__delitem__方法
    del g['a']

